Imports System.Collections.Generic
Imports System.Text
Imports System.Windows.Forms
Imports System.IO

Public Class DemosTools

	#Region "Methods"

    Shared Sub New()
        
    End Sub

	''' <summary>
	''' Sets enabled state of specified menu item.
	''' </summary>
	Public Shared Sub SetMenuEnabledState(item As ToolStripItem, enabled As Boolean)
		Dim dropDownItem As ToolStripDropDownItem = TryCast(item, ToolStripDropDownItem)
		If dropDownItem IsNot Nothing AndAlso dropDownItem.DropDownItems.Count > 0 Then
			For i As Integer = 0 To dropDownItem.DropDownItems.Count - 1
				dropDownItem.DropDownItems(i).Enabled = enabled
			Next
		Else
			item.Enabled = enabled
		End If
	End Sub

	''' <summary>
	''' Shows a error(exception) message.
	''' </summary>
	''' <param name="caption">MessageBox caption.</param>
	''' <param name="ex">The exception.</param>
	Public Shared Sub ShowErrorMessage(caption As String, ex As Exception)
		MessageBox.Show(ex.Message, caption, MessageBoxButtons.OK, MessageBoxIcon.[Error])
	End Sub

	''' <summary>
	''' Shows a error(exception) message.
	''' </summary>
	''' <param name="caption">MessageBox caption.</param>
	''' <param name="message">The text of error.</param>
	Public Shared Sub ShowErrorMessage(caption As String, message As String)
		MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.[Error])
	End Sub

	''' <summary>
	''' Shows a error(exception) message.
	''' </summary>
	''' <param name="ex">The exception.</param>
	Public Shared Sub ShowErrorMessage(ex As Exception)
		ShowErrorMessage("Error", ex)
	End Sub

	''' <summary>
	''' Shows a error(exception) message.
	''' </summary>
	''' <param name="ex">The exception.</param>
	''' <param name="filename">A filename.</param>
	Public Shared Sub ShowErrorMessage(ex As Exception, filename As String)
		MessageBox.Show(String.Format("{0} ({1})", ex.Message, Path.GetFileName(filename)), "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
	End Sub

	''' <summary>
	''' Shows a warning message.
	''' </summary>
	''' <param name="caption">MessageBox caption.</param>
	''' <param name="message">The message.</param>
	Public Shared Sub ShowWarningMessage(caption As String, message As String)
		MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning)
	End Sub

	''' <summary>
	''' Shows a warning message.
	''' </summary>
	''' <param name="message">The message.</param>
	Public Shared Sub ShowWarningMessage(message As String)
		ShowWarningMessage("Warning", message)
	End Sub

	''' <summary>
	''' Shows an information message.
	''' </summary>
	''' <param name="caption">MessageBox caption.</param>
	''' <param name="message">The message.</param>
	Public Shared Sub ShowInfoMessage(caption As String, message As String)
		MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Information)
	End Sub

	''' <summary>
	''' Shows an information message.
	''' </summary>
	''' <param name="message">The message.</param>
	Public Shared Sub ShowInfoMessage(message As String)
		ShowInfoMessage("Information", message)
	End Sub

	''' <summary>
	''' Sets the directory to the initial image directory.
	''' </summary>
	''' <param name="fileDialog">Dialog box from which the user can select a file.</param>
	Public Shared Sub SetDemoImagesFolder(fileDialog As FileDialog)
		Dim imagesFolder As String = FindDemoImagesFolder()
		If imagesFolder <> "" Then
			fileDialog.InitialDirectory = imagesFolder
		End If
	End Sub

	''' <summary>
	''' Sets the directory to the initial image directory.
	''' </summary>
	''' <param name="folderBrowserDialog">Dialog box from which the user can select a file.</param>
	Public Shared Sub SetDemoImagesFolder(folderBrowserDialog As FolderBrowserDialog)
		Dim imagesFolder As String = FindDemoImagesFolder()
		If imagesFolder <> "" Then
			folderBrowserDialog.SelectedPath = imagesFolder
		End If
	End Sub

	''' <summary>
	''' Returns a full path to the initial image directory.
	''' </summary>
	''' <returns>
	''' Full path to the initial image directory,
	''' or empty string, if directory not found.
	''' </returns>
	Private Shared Function FindDemoImagesFolder() As String
		Try
			Dim demoImagesFolder As String = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName)
			Dim imagesFolder As String = Path.Combine(demoImagesFolder, "..\..\..\Images")
			If Directory.Exists(imagesFolder) Then
				Return Path.GetFullPath(imagesFolder)
			End If
		Catch
		End Try

		Return ""
	End Function

	#End Region

End Class
